package cn.corgy.module.serialize.json;

import cn.corgy.module.serialize.Serializer;
import com.alibaba.fastjson.JSON;

import java.nio.charset.StandardCharsets;

/**
 * json序列化
 */
public class JsonSerializer implements Serializer {
    @Override
    public byte[] serialize(Object obj) {
        String json = JSON.toJSONString(obj);
        return json.getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> clazz) {
        return JSON.parseObject(bytes, clazz);
    }
}
